package com.yygo.model;

import com.yygo.model.enums.AttachmentType;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by tiansha on 2015/6/18.
 */
@Entity
@Table(name = "attachment")
public class Attachment extends BaseObject {
    private static final long serialVersionUID = -4167421578910323556L;
    private Long id;
    private Date time;
    private String name;
    private String fileName;
    private String operator;

    private AttachmentType type;

    private LoanRequest loanRequest;

    public Attachment() {}

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column
    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    @Column(name="attachment_type")
    @Enumerated(EnumType.STRING)
    public AttachmentType getType() {
        return type;
    }

    public void setType(AttachmentType type) {
        this.type = type;
    }

    @Column(length = 50)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name="file_name", length = 50)
    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    @Column(length = 20)
    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    @ManyToOne
    @JoinColumn(name="req_id")
    public LoanRequest getLoanRequest() {
        return loanRequest;
    }

    public void setLoanRequest(LoanRequest loanRequest) {
        this.loanRequest = loanRequest;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Attachment feedback = (Attachment) o;

        if (fileName.equals(feedback.fileName)) {
            return true;
        }

        return false;
    }

    public int hashCode() {
        int result = 3;
        result = 57 * result + (fileName != null ? fileName.hashCode() : 0);
        return result;
    }

    public String toString() {
        return "Attachment{" +
                "fileName=" + fileName +
                '}';
    }

}
